package com.tz.service;

import com.tz.dao.CategoryDao;
import com.tz.entity.Category;
import com.tz.util.AcUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2016/8/4.
 */
@Service
@Transactional
public class CategoryServiceImpl implements CategoryService{

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public List<Category> findAllCategory() {
        //查找父类category
        Category category = categoryDao.findCategoryById(0);
        List<Category> categories = categoryDao.findCategoryByCategoryId(0);
        List<Category> chidren = null;
        for(Category c : categories){
            chidren = categoryDao.findCategoryByCategoryId(c.getId());
            c.setChildren(chidren);
            for (Category ch : c.getChildren()){
                ch.setChildren(null);
            }
        }
        category.setChildren(categories);
        return categories;
    }
}
